package threaddemo;

public class Trainee implements Runnable{

	private Integer paperCount;
//	private Lock lock=new ReentrantLock();
	public Integer getPaperCount() {
		return paperCount;
	}
	public void setPaperCount(Integer paperCount) {
		this.paperCount = paperCount;
	}

	public Trainee() {
		super();
	}

	public Trainee(Integer paperCount) {
		super();
		this.paperCount = paperCount;
	}
	
	
	public void run(){
//		shit();
		
		
		synchronized(paperCount){
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		lock.lock();
		if(paperCount>0){
			paperCount--;
			System.out.println(Thread.currentThread().getName()+" uses one piece of paper");
		}
		else{
			System.out.println(Thread.currentThread().getName()+" have no paper");
		}
	}
//		lock.unlock();
	}
	
	public synchronized void shit(){
		try {
			Thread.sleep(10);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(paperCount>0){
			paperCount--;
			System.out.println(Thread.currentThread().getName()+" uses one piece of paper");
		}
		else{
			System.out.println(Thread.currentThread().getName()+" have no paper");
		}
	}
	
	
//	private void shit(){
//		synchronized(paperCount){
//			try {
//				Thread.sleep(10);
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//			if(paperCount>0){
//				paperCount--;
//				System.out.println(Thread.currentThread().getName()+" uses one piece of paper");
//			}
//			else{
//				System.out.println(Thread.currentThread().getName()+" have no paper");
//			}
//		}
//	}
	
	
}
